import { defineStore } from "pinia";
import { resDetailsData, resHomeData, } from "@/api/homes";
import router from "@/routers";
// import {  ElMessage } from 'element-plus';
// const num =53;

const useDataStore = defineStore('detail', {
  state() {
    return {
      HomeData: JSON.parse(localStorage.getItem('home')) || [],
      DetailData: [],
    };
  },
  actions: {
    async getHomeData() {
      let result = await resHomeData();
      if (result.status == 200) {
        this.HomeData = result.data.data;
        localStorage.setItem("home", JSON.stringify(this.HomeData));
        return 'ok';
      } else {
        return Promise.reject(new Error(result.message));
      }
    },
    async getDetailData(corId) {
      // const num=Number(corrNo);
      // router.push({path:'/front',query: {corId:corId}})
      let result = await resDetailsData(corId);
      if (result.status == 200) {
        console.log("课程详情数据", result.data.data)
        this.DetailData = result.data.data;
        return 'ok';
      } else {
        return Promise.reject(new Error(result.message));
      }
    },
  },
  getters: {
    theHome: state => state.HomeData,
    theDetail: state => state.DetailData,
  }
});

export default useDataStore;

// route,query(corId)
//cost detail=theDetail.data

// {{detail.name }}
// {{detail.manindesigner}}